package com.bxshey.happyTown.result;

import lombok.Data;

@Data
public class Result<T> {
    Integer code;
    String msg;
    T data;

    public static <T> Result<T> success(ResultEnum resultEnum,T data) {
        Result<T> r = new Result<>();
        r.msg = resultEnum.msg;
        r.code = resultEnum.code;
        r.data = data;
        return r;
    }

    public static <T> Result<T> success(ResultEnum resultEnum) {
        Result<T> r = new Result<>();
        r.msg = resultEnum.msg;
        r.code = resultEnum.code;
        return r;
    }
    public static <T> Result<T> success(String msg,T data) {
        Result<T> r = new Result<>();
        r.code = 200;
        r.msg = msg;
        r.data = data;
        return r;
    }
    public static <T> Result<T> success(T data) {
        Result<T> r = new Result<>();
        r.code = 200;
        r.msg = "成功";
        r.data = data;
        return r;
    }

    public static <T> Result<T> error() {
        Result<T> r = new Result<>();
        r.code = 400;
        r.msg = "失败";
        return r;
    }
    public static <T> Result<T> error(Integer code,String msg) {
        Result<T> r = new Result<>();
        r.code = code;
        r.msg = msg;
        return r;
    }
}


